package com.wenli.lt.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.wenli.lt.entity.Grade;
import com.wenli.lt.mapper.GradeMapper;
import com.wenli.lt.service.IGradeService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.UUID;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author lt
 * @since 2021-03-21
 */
@Service
public class GradeServiceImpl extends ServiceImpl<GradeMapper, Grade> implements IGradeService {
    @Autowired
    GradeMapper gradeMapper;

    @Override
    public boolean addGrade(Grade grade) {
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.eq("gradeName",grade.getGradeName()+"级");
        Grade grade1 = gradeMapper.selectOne(queryWrapper);
        if (ObjectUtils.isNotEmpty(grade1)){
            return false;
        }else {
            grade.setGradeId(UUID.randomUUID().toString().replace("-",""));
            grade.setGradeName(grade.getGradeName()+"级");
            return 1 == gradeMapper.insert(grade);

        }

    }

    @Override
    public List<Grade> getGrade() {
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.select().orderByAsc();
        return  gradeMapper.selectList(queryWrapper);
    }
}
